package org.hamster.multidropbox.mainView.view.comp
{
	import flash.events.MouseEvent;
	
	import org.hamster.multidropbox.dropbox.vo.AppDropboxClient;
	import org.hamster.multidropbox.dropbox.vo.AppDropboxFile;
	import org.hamster.multidropbox.mainView.event.MainViewEvent;
	
	import spark.components.Group;
	import spark.components.supportClasses.ItemRenderer;
	
	[Event(type="org.hamster.multidropbox.mainView.event.MainViewEvent", name="fileItemDoubleClick")]
	[Event(type="org.hamster.multidropbox.mainView.event.MainViewEvent", name="fileItemShowDetails")]
	[Event(type="org.hamster.multidropbox.mainView.event.MainViewEvent", name="fileItemHideDetails")]
	
	public class BaseFileListItemRenderer extends ItemRenderer implements IFileListItemRenderer
	{
		private var file:AppDropboxFile;
		
		public function BaseFileListItemRenderer()
		{
			super();
			this.addEventListener(MouseEvent.ROLL_OVER, this_rollOverHandler);
			this.addEventListener(MouseEvent.ROLL_OUT, this_rollOutHandler);
			this.addEventListener(MouseEvent.DOUBLE_CLICK, this_doubleClickHandler);
			this.doubleClickEnabled = true;
		}
		
		override public function set data(value:Object):void
		{
			if (file != value) {
				super.data = value;
				file = AppDropboxFile(value);
				if (file != null) {
					updateComponent();
				}
			}
		}
		
		override public function get data():Object
		{
			return file;
		}
		
		public function get dropboxClient():AppDropboxClient
		{
			return file.client;
		}
		
		public function get dropboxFile():AppDropboxFile
		{
			return file;
		}
		
		public function updateComponent():void
		{
			
		}
		
		private function this_rollOverHandler(event:MouseEvent):void
		{
			var disEvt:MainViewEvent = new MainViewEvent(MainViewEvent.FILE_ITEM_SHOW_DETIALS, true);
			disEvt.dropboxFile = file;
			this.dispatchEvent(disEvt);
		}
		
		private function this_rollOutHandler(event:MouseEvent):void
		{
			var disEvt:MainViewEvent = new MainViewEvent(MainViewEvent.FILE_ITEM_HIDE_DETIALS, true);
			disEvt.dropboxFile = file;
			this.dispatchEvent(disEvt);
		}
		
		private function this_doubleClickHandler(event:MouseEvent):void
		{
			var disEvt:MainViewEvent = new MainViewEvent(MainViewEvent.FILE_ITEM_DOUBLE_CLICK, true);
			disEvt.dropboxFile = file;
			this.dispatchEvent(disEvt);
		}
	}
}